#!/usr/bin/env python
from antpy import *

@state
def search():
    Sense('Ahead', next, choose_3_ways(search), 'Food')
    Move(next, search)
    PickUp(go_home, search)

@state
def choose_3_ways(cnt):
    Flip(3, next, choose_2_ways(cnt))
    Turn('Left', cnt)

@state
def choose_2_ways(cnt):
    Flip(2, next, forward(cnt))
    Turn('Right', cnt)

@state
def forward(cnt):
    Move(cnt, choose_3_ways(cnt))
    
@state
def go_home():
    Sense('Ahead', next, choose_3_ways(go_home), 'Home')
    Move(next, go_home)
    Drop(search)


if __name__ == '__main__':
    search()
    go_home()
    for line in Program.output():
        print line

